/*
 *此javaCode由YMS-JDBC替换工具生成，原mapper位置com.yonyou.ucf.mdf.app.isvdxq.other.mapper.OrgUnitMapper
 */
package com.yonyou.ucf.mdf.app.isvdxq.other.mapper.impl;

import com.yonyou.iuap.yms.api.IYmsJdbcApi;
import com.yonyou.iuap.yms.param.ResultSetProcessor;
import com.yonyou.iuap.yms.param.SQLParameter;
import com.yonyou.iuap.yms.processor.AutoBeanListProcessor;
import com.yonyou.iuap.yms.processor.AutoBeanProcessor;
import com.yonyou.iuap.yms.processor.ColumnProcessor;
import com.yonyou.iuap.yms.replace.CollectionUtil;
import com.yonyou.ucf.mdf.app.isvdxq.other.entity.OrgUnitEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.sql.Types;
import java.util.List;

@Repository
public class OrgUnitMapperImpl {
    
    @Autowired
    private IYmsJdbcApi ymsJdbcApi;
    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.OrgUnitMapper.selectByIds
    
    public List<OrgUnitEntity> selectByIds(List<String> strList, String tenant_id) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" select * from dxqyy_orgunit where dr=0 and `ytenant_id` = ? ");
		parameter.addParam(tenant_id);
		if (CollectionUtil.isNotEmpty(strList)) {
			sqlBuilder.append(" and `id` in ( ");
			String separator0 = " , ";
			for (int index = 0; index < strList.size(); index++) {
				String item = strList.get(index);
				sqlBuilder.append(" ? ");
				parameter.addParam(item);
				if (index < strList.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
			sqlBuilder.append(" ) ");
		}

        
        String sql = sqlBuilder.toString();
        ResultSetProcessor processor = new AutoBeanListProcessor(new OrgUnitEntity());
        return (List<OrgUnitEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.OrgUnitMapper.updateByPrimaryKey
    
    public int updateByPrimaryKey(OrgUnitEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "update dxqyy_orgunit set `parent` = ?, `parent_name` = ?, `dr` = ?, `enable` = ?, `effectivedate` = ?, `pubts` = ?, `code` = ?, `orgid` = ?, `orgtype` = ?, `name` = ?, `shortname` = ?, `description` = ?, `address` = ?, `companytype` = ?, `companytype_name` = ?, `exchangerate` = ?, `accountOrg` = ?, `exchangerate_name` = ? where `id` = ? and `ytenant_id` = ?\n";
        parameter.addParamWithType(record.getParent(), Types.VARCHAR);
		parameter.addParamWithType(record.getParent_name(), Types.VARCHAR);
		parameter.addParamWithType(record.getDr(), Types.INTEGER);
		parameter.addParamWithType(record.getEnable(), Types.INTEGER);
		parameter.addParamWithType(record.getEffectivedate(), Types.VARCHAR);
		parameter.addParamWithType(record.getPubts(), Types.VARCHAR);
		parameter.addParamWithType(record.getCode(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrgid(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrgtype(), Types.BIT);
		parameter.addParamWithType(record.getName(), Types.VARCHAR);
		parameter.addParamWithType(record.getShortname(), Types.VARCHAR);
		parameter.addParamWithType(record.getDescription(), Types.VARCHAR);
		parameter.addParamWithType(record.getAddress(), Types.VARCHAR);
		parameter.addParamWithType(record.getCompanytype(), Types.VARCHAR);
		parameter.addParamWithType(record.getCompanytype_name(), Types.VARCHAR);
		parameter.addParamWithType(record.getExchangerate(), Types.VARCHAR);
		parameter.addParamWithType(record.getAccountOrg(), Types.VARCHAR);
		parameter.addParamWithType(record.getExchangerate_name(), Types.VARCHAR);
		parameter.addParamWithType(record.getId(), Types.VARCHAR);
		parameter.addParamWithType(record.getTenant_id(), Types.VARCHAR);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.OrgUnitMapper.insert
    
    public int insert(OrgUnitEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "insert into dxqyy_orgunit (`id`, `parent`,  `parent_name`, `dr`,  `enable`, `effectivedate`,  `pubts`, `code`,  `orgid`, `orgtype`, `name`,  `shortname`, `description`,  `address`, `companytype`,  `companytype_name`, `exchangerate`,  `exchangerate_name`,`accountOrg`,`tenant_id`,`ytenant_id`) values (?, ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?)\n";
        parameter.addParamWithType(record.getId(), Types.VARCHAR);
		parameter.addParamWithType(record.getParent(), Types.VARCHAR);
		parameter.addParamWithType(record.getParent_name(), Types.VARCHAR);
		parameter.addParamWithType(record.getDr(), Types.INTEGER);
		parameter.addParamWithType(record.getEnable(), Types.INTEGER);
		parameter.addParamWithType(record.getEffectivedate(), Types.VARCHAR);
		parameter.addParamWithType(record.getPubts(), Types.VARCHAR);
		parameter.addParamWithType(record.getCode(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrgid(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrgtype(), Types.BIT);
		parameter.addParamWithType(record.getName(), Types.VARCHAR);
		parameter.addParamWithType(record.getShortname(), Types.VARCHAR);
		parameter.addParamWithType(record.getDescription(), Types.VARCHAR);
		parameter.addParamWithType(record.getAddress(), Types.VARCHAR);
		parameter.addParamWithType(record.getCompanytype(), Types.VARCHAR);
		parameter.addParamWithType(record.getCompanytype_name(), Types.VARCHAR);
		parameter.addParamWithType(record.getExchangerate(), Types.VARCHAR);
		parameter.addParamWithType(record.getExchangerate_name(), Types.VARCHAR);
		parameter.addParamWithType(record.getAccountOrg(), Types.VARCHAR);
		parameter.addParamWithType(record.getTenant_id(), Types.VARCHAR);
		parameter.addParamWithType(record.getTenant_id(), Types.VARCHAR);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.OrgUnitMapper.selectCount
    
    public int selectCount(String id, String tenant_id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select count(1) from dxqyy_orgunit where `id`=? and `ytenant_id` = ?;\n";
        parameter.addParam(id);
		parameter.addParam(tenant_id);

        ResultSetProcessor processor = new ColumnProcessor(int.class);
        return (int) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.OrgUnitMapper.selectById
    
    public OrgUnitEntity selectById(String id, String tenant_id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxqyy_orgunit where `id`=? and `ytenant_id` = ?;\n";
        parameter.addParam(id);
		parameter.addParam(tenant_id);

        ResultSetProcessor processor = new AutoBeanProcessor(new OrgUnitEntity());
        return (OrgUnitEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.OrgUnitMapper.deleteByPrimaryKey
    
    public int deleteByPrimaryKey(String id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "delete from dxqyy_orgunit where `id` = ?\n";
        parameter.addParamWithType(id, Types.VARCHAR);

        
        return ymsJdbcApi.update(sql, parameter);
    }

}
